/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carrello.impl.boundary.manager;

import carrello.impl.boundary.AbstractUI;
import carrello.impl.controller.manager.ViewSalesCTRL;
import carrello.model.association.Invoice;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Usman
 */
public class ViewSalesUI extends AbstractUI{
    
    private List<Invoice> invoices;
    private LinkedList<LinkedList<String>> parameters = null;
    
    public LinkedList<LinkedList<String>> getparameters () {
        return parameters;
    }
    private void getSalesData () {
        parameters = new LinkedList<LinkedList<String>> ();
        invoices = ViewSalesCTRL.getAllInvoices();
        for ( Invoice i: invoices ) {
            LinkedList<String> parameter = new LinkedList<String> ();
            parameter.add(i.getProductname());
            Integer qty = i.getQuantity();
            parameter.add(qty.toString());
            double cost = Double.parseDouble(i.getCost());
            cost *= qty;
            parameter.add(String.valueOf(cost));
            parameters.add(parameter);
        }
    }
    @Override
    public String execute () {
        if ( !getSessionIsLoggedIn())
            return ERROR;
        getSalesData ();
        return INPUT;
    }
}
